package com.ljh.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ljh.mapper.listMapper;
import com.ljh.pojo.Collection;
import com.ljh.pojo.SList;
import com.ljh.pojo.Song;
import com.ljh.service.ListService;
import com.ljh.service.UserService;
import com.ljh.utils.Result;
import com.ljh.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ListServiceImpl extends ServiceImpl<listMapper,SList> implements ListService {

    @Autowired
    listMapper listMapper;
    @Autowired
    UserService userService;

    @Override
    public List<SList> findListByStyle(String style) {
        List<SList> listByStyle = listMapper.findListByStyle(style);
        return listByStyle;
    }

    @Override
    public AListSongVo findSongByListId(Integer id){
        AListSongVo aListSongVo = new AListSongVo();
        SList sList = new SList();
        List<IntoSongListVo> songByListId = listMapper.findSongByListId(id);
        System.out.println(songByListId);
        if(songByListId!=null&&songByListId.size()!=0){
            sList.setListTittle(songByListId.get(0).getListTittle());
            sList.setListIntroduce(songByListId.get(0).getListIntroduce());
            sList.setListPhoto(songByListId.get(0).getListPhoto());
            UserVo aUserById = userService.findAUserById(Integer.parseInt(songByListId.get(0).getUserId()));
            aListSongVo.setSList(sList);
            aListSongVo.setSongListVos(songByListId);
            aListSongVo.setUserVo(aUserById);
        }else{
            ListInfoTittle songTittleInfo = listMapper.findSongTittleInfo(id);
            System.out.println(songTittleInfo);
            sList.setListPhoto(songTittleInfo.getListPhoto());
            sList.setListIntroduce(songTittleInfo.getListIntroduce());
            sList.setListTittle(songTittleInfo.getListTittle());
            aListSongVo.setSList(sList);
            UserVo userVo = new UserVo();
            userVo.setUserName(songTittleInfo.getUserName());
            userVo.setUserPhoto(songTittleInfo.getUserPhoto());
            aListSongVo.setUserVo(userVo);
        }
        return aListSongVo;
    }

    @Override
    public List<SList> findPerfer() {
        return listMapper.findPerfer(10);
    }

    @Override
    public List<SList> findRandom() {
        return listMapper.findPerfer(15);
    }

    public List<SList> findThree(Integer id){
        return listMapper.findNum(3,id);
    }

    @Override
    public List<MyListLike> findMyListLike(Integer id) {
        return listMapper.findMyListLike(id);
    }

    @Override
    public List<SList> findListById(Integer id) {
        return listMapper.findListById(id);
    }

    @Override
    public List<SList> findListLikeById(Integer id) {
        return listMapper.findListLikeById(id);
    }

    @Override
    public void insertNewList(NewList newList) {
        listMapper.insertNewList(newList);
    }

    /**
     * 收藏歌单
     * @param userId
     * @param listId
     */
    @Override
    public void insertLike(Integer userId, Integer listId) {
        listMapper.insertLike(userId,listId);
    }

    /**
     * 通过两个列之间的关系查找有无
     * @param userId
     * @param listId
     * @return
     */
    @Override
    public LikeUserVo findGuanxiByUserList(Integer userId,Integer listId){
        LikeUserVo guanxiByUserList = listMapper.findGuanxiByUserList(userId, listId);
        return guanxiByUserList;
    }

    @Override
    public void insertSongToList(Integer listId, Integer songId) {
        listMapper.insertSongToList(listId, songId);
    }

    @Override
    public List_SongVo findListSongVo(Integer listId, Integer songId) {
        List_SongVo listSongVo = listMapper.findListSongVo(listId, songId);
        return listSongVo;
    }

    @Override
    public void deleteListById(Integer userId) {
        listMapper.deleteListById(userId);
    }

    @Override
    public void deleteLikeById(Integer userId) {
        listMapper.deleteLikeById(userId);
    }

    @Override
    public void deleteListByListId(Integer listId) {
        listMapper.deleteListByListId(listId);
    }

    @Override
    public void deleteSongListBylistId(Integer listId) {
        listMapper.deleteSongListBylistId(listId);
    }

    @Override
    public void deleteLikeBylistId(Integer listId) {
        listMapper.deleteLikeBylistId(listId);
    }

    @Override
    public void updateListPhoto(String listPhoto, Integer listId) {
        listMapper.updateListPhoto(listPhoto,listId);
    }

    @Override
    public void deleteListSongBySongId(Integer songId) {
        listMapper.deleteListSongBySongId(songId);
    }

    @Override
    public SList findSlistByListId(Integer listId) {
        SList slistByListId = listMapper.findSlistByListId(listId);
        return slistByListId;
    }

    @Override
    public void deleteListInfoSong(Integer songId, Integer listId) {
        listMapper.deleteListInfoSong(songId, listId);
    }

    @Override
    public void updateListInfo(SList slist) {
        listMapper.updateListInfo(slist);
    }

    @Override
    public List<Song> findSongListInsert(String songName) {
        songName = "%"+songName+"%";
        return listMapper.findSongListInsert(songName);
    }

    @Override
    public void songToInsertList(Integer listId, Integer songId) {
        listMapper.songToInsertList(listId, songId);
    }

    @Override
    public List<SexVo> findListStyle() {
        return listMapper.findListStyle();
    }
}
